﻿<%@ Page Title="回货计划" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/report/AllocationDetail.css" rel="stylesheet" />
    <link href="../assets/css/plugins/jQuery-DataTables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />

    <style>
        .system-box .right-side {
            width: 100%;
        }

        .condition, .condition-title {
            border-bottom: 1px solid #dfdfdd;
        }


        .form-group label {
            margin-left: 5px;
            padding-left: 1px;
            padding-right: 1px;
        }

        .footable th,
        .footable td {
            padding: 8px;
        }

        .modal-dialog {
            width: 500px;
        }

        @media (min-width: 750px) {
            .modal-dialog {
                width: 440px;
            }
        }

        #addWindow .form-group {
            margin-bottom: 4px;
        }

        #addWindow .form-group label {
            max-width: 100%;
        }

        #search-artnum {
            display: inline-block;
            width: 355px;
            position: absolute;
            left: 58px;
            top: 5px;
            color: #333;
            background-color: #fff;
            border-color: #ccc;
            padding: 6px;
            border-radius: 3px;
        }

        #table {
            margin-top: 0 !important;
            border-left: 0;
            border-right: 0;
        }

        .bg_blue {
            background-color: #110ffd;
        }

        .bg_green {
            background-color: #07980e;
        }

        .bg_red {
            background-color: #fe0402;
        }
        /*.condition1 label{ width: 40px; text-align: right;}
        .condition1 select{ width: 129px !important;display: inline-block;}
        .condition1 input{ display: inline-block;}
        .condition1 {padding: 2px 0}*/
        .condition-container {
            padding-bottom: 5px;
        }

        .dataTables_paginate {
            padding-right: 10px;
            padding-top: 5px;
        }

        .dataTables_paginate {
            padding-top: 15px;
        }

        .dataTables_scroll tr.selected {
            border-left: 4px solid #7acf89 !important;
        }

        .dataTables_scroll tr.selected td {
            background: #dff0d8 !important;
            color: #222121 !important;
        }

        .dataTables_scrollHead {
            background-color: #ffffff;
        }

        .dataTables_wrapper {
            font-size: 12px;
        }
        /*.dataTables_wrapper div.dataTables_processing {top: 70%;}*/
        .footer {
            width: 100%;
        }

        .popLayer .glyphicon {
            font-size: 12px;
        }

        .popLayer .glyphicon-arrow-down {
            left: 100px;
            top: -1px;
        }

        .popLayer .glyphicon-arrow-left {
            left: -13px;
            top: -45px;
        }

        .popLayer .glyphicon-arrow-right {
            top: -45px;
            left: 212px;
        }

        .popLayer .glyphicon-arrow-up {
            left: 95px;
            top: -96px;
        }

        .popLayer .infoBtn .dot {
            -ms-border-radius: 24px;
            border-radius: 24px;
            height: 20px;
            width: 20px;
            display: inline-block;
        }

        .popLayer .infoBtn .tips {
            width: 50px;
            height: 20px;
            display: inline-block;
            position: relative;
            top: -5px;
            left: 4px;
        }

        .popLayer .infoBtn {
            position: relative;
            top: 45px;
        }

        .popLayer .infotitle {
            background-color: #07980e;
            z-index: 2;
            color: #ffffff;
            text-align: center;
            left: 20px;
            width: 175px;
            position: relative;
            top: 10px;
            font-size: 12px;
        }

        .popLayer .weekinfo .info {
            padding: 15px 0px 0px 0px;
        }

        .popLayer .weekinfo .info label {
            margin-bottom: 0px;
            font-weight: normal;
            font-size: 12px;
        }

        .popLayer .weekinfo .leftinfo {
            width: 95px;
            border-right: 1px solid #e7eaec;
        }

        .popLayer .weekinfo .rightinfo {
            width: 113px;
            padding-left: 2px;
        }

        .popLayer .weekinfo {
            width: 212px;
            display: inline-block;
            border: solid #000 1px;
            padding-left: 2px;
        }

        .popLayer {
            padding-left: 5px;
            font-size: 12px;
        }

        .popLayer tr {
            height: 95px;
        }

        .popLayer tr td {
            width: 224px;
            border: 1px solid #ffffff;
        }

        .system-box .right-side {
            overflow: hidden;
        }

        .system-box {
            min-width: 940px;
        }

        .table-container {
            background-color: #ffffff;
        }

        .yuce span {
            color: #ffffff;
            padding-left: 2px;
            padding-right: 2px;
            margin-left: 1px;
            cursor: default;
        }

        .condition-container {
            padding-bottom: 0px;
        }

        .condition-container .row {
            margin-right: 0px;
            margin-left: 0px;
        }

        .condition-container .col-xs-3 {
            max-width: 235px;
        }

        .condition-container .form-group {
            margin-bottom: 0;
        }

        .condition-container .form-group label {
            margin-right: 3px;
        }
        /*下拉框覆盖样式*/
        .backselect {
            color: #333;
            background-color: #fff;
            border-color: #ccc;
            padding: 5px 8px;
        }

        ul.dropdown-menu li {
            border: 1px solid #f1f1f1
        }

        ul.dropdown-menu > li > a {
            margin: 0;
        }

        .td-w60 {
            width: 60px;
            max-width: 60px;
        }

        .td-w70 {
            width: 70px;
            max-width: 70px;
        }

        .td-w80 {
            width: 80px;
            max-width: 80px;
        }

        .td-w100 {
            width: 100px;
            max-width: 100px;
        }

        .condition-container .form-group {
            padding: 0;
            margin: 0;
        }

        .font-yellow {
            color: goldenrod;
            font-weight: bold;
        }

        .font-red {
            color: red;
            font-weight: bold;
        }

        .tips {
            line-height: normal;
            color: #bc7b21;
            background: #fffdcd;
            padding: 5px;
            margin:0px 8px;
            border-bottom: 1px solid #e5e5e5;
        }

        .fa-lightbulb-o::before {
            content: "\f0eb";
        }
    </style>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <%-- 按钮--%>
            <div class="btns-container"></div>
            <%--新增弹出框begin--%>
            <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content animated bounceInRight">
                        <div class="modal-header">
                            <span class="editTitle"></span>
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
                        </div>
                        <div id="message" style="display: none"></div>
                        <div class="modal-body clearfix">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">供应商:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_ShortName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">仓库:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_StockName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">订单号:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_OrderBillNo" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">货号名称:</label>
                                    </div>
                                    <div class="col-sm-6 ">
                                        <input type="text" id="text_MaterialShortName" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">货号:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_MaterialID" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">到货日期:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_StartShipDate" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">到货数量:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_RemainQty" class="form-control input-sm" disabled />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class=" control-label input-sm">调整后到货日期:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_AdjustStartShipDate" name="text_AdjustStartShipDate" datacol="yes" err="调整后到货日期" checkexpession="NotNull" maxlength="10" class="form-control required input-sm" />
                                        <input type="text" id="text_OldAdjustStartShipDate" name="text_OldAdjustStartShipDate" class="hide" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 text-right no-padding">
                                        <label class="control-label input-sm">调整后到货数量:</label>
                                    </div>
                                    <div class="col-sm-6">
                                        <input type="text" id="text_AdjustRemainQty" name="text_AdjustRemainQty" placeholder="" datacol="yes" err="调整后到货数量" checkexpession="NotNull" maxlength="10" class="form-control required input-sm" />
                                        <input type="text" id="text_OldAdjustRemainQty" name="text_OldAdjustRemainQty" placeholder="" class="hide" />
                                    </div>
                                </div>
                            </form>
                            <br />
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                            <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <%--新增弹出框end--%>
            <%--查询条件begin--%>
            <div class="condition-container" style="overflow: visible;">
                <form class="form-horizontal">
                    <div class="row">
                        <div class="form-group col-xs-3">
                            <label for="search-Area" class="control-label">供应商</label>
                            <select id="search-ShortNames" class="form-control selectpicker" data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-xs-3">
                            <label for="search-Kind" class="control-label">大类</label>
                            <select id="search-KindNames" class="form-control selectpicker " data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-xs-3">
                            <label for="search-Item" class="control-label">子项</label>
                            <select id="search-ItemNames" class="form-control selectpicker" data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label" style="float: left">货号</label>
                            <div style="width: 200px; float: left; margin-left: 4px; margin-top: 4px;">
                                <div class="input-group text-center">
                                    <input type="text" class="form-control" placeholder="多个用','分隔" id="search-MaterialIDs">
                                    <div class="input-group-btn no-padding">
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
                                    </div>
                                </div>
                            </div>
                            <div style="clear: both; margin-bottom: 8px"></div>
                        </div>
                    </div>
                </form>
                <div class="row tips">
                    <i class="fa fa-lightbulb-o"></i>
                    计划到货日期/调整后到货日期为红色时表示超时，计划到货数量/调整后到货数量为橙色时表示数量有变更！
                </div>
            </div>
            <%--查询条件end--%>
            <div class="right-content-box clearfix">
                <div class="ibox-content ">
                    <table class="footable table table-bordered">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>
            <div class="pageControl"></div>
        </div>
    </div>

</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/bootstrap-suggest.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/itemSuggest.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/jquery.dataTables.min.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/dataTables.bootstrap.js"></script>
    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>

    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                rScroll();
            });
            //要提取到公共类
            var nmCommonBindList = function (controller, action, params, els, value, text, size, callback) {
                Y.API2(controller, action, params, function (data) {
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        var html = '';
                        data.map(function (item) {
                            html += '<option value=' + item[value] + '>' + item[text] + '</option>';
                        });
                        els.map(function (item) {
                            $(item).append(html);
                            $(item).selectpicker({ size: size || 8, 'title': '请选择' });
                            $(item).selectpicker('refresh');
                        });
                        if (typeof callback === "function") {
                            callback();
                        }
                    }
                });
            }

            var q_shortNames = "", q_kindNames = "", q_itemNames = "", temp_values;
            var SetQueryValues = function () {
                q_shortNames = q_kindNames = q_itemNames = "";
                temp_values = $('#search-ShortNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_shortNames = temp_values.join(',');
                }
                temp_values = $('#search-KindNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_kindNames = temp_values.join(',');
                }
                temp_values = $('#search-ItemNames').val();
                if (temp_values != "" && temp_values != null) {
                    q_itemNames = temp_values.join(',');
                }
            }

            //供应商
            var nmGetShortNames = function (els, size, callback) {
                nmCommonBindList('ReturPlan', 'GetShortNames', {}, els, 'VendCustID', 'ShortName', size, callback);
            }
            //大类
            var nmGetKindInfo = function (els, size, callback) {
                nmCommonBindList('Common', 'GetKindInfo', {}, els, 'KindID', 'KindName', size, callback);
            }
            //子项
            var nmGetItemInfo = function (els, params, size, callback) {
                nmCommonBindList('Common', 'GetItemInfo', { kindIds: params }, els, 'ItemorSub', 'ItemorSub', size, callback);
            }

            var itemSuggest_MaterialIDs = new itemSuggest();
            //货号
            var nmGetMaterialIDs = function () {
                SetQueryValues();
                var param = {
                    ShortNames: q_shortNames,
                    KindNames: q_kindNames,
                    ItemNames: q_itemNames
                }
                itemSuggest_MaterialIDs.destroy();
                itemSuggest_MaterialIDs.SetBtnHide();
                itemSuggest_MaterialIDs.initSuggestPram('search-MaterialIDs', 'ReturPlan', 'GetMaterials', 'MaterialID', 'MaterialID', param);
            }

            //初始化表格
            nmGetShortNames(['#search-ShortNames']);
            nmGetKindInfo(['#search-KindNames']);
            nmGetItemInfo(['#search-ItemNames']);
            nmGetMaterialIDs();

            //大类获取小类
            $(document).on("change", "#search-KindNames", function () {
                //console.log("触发了原生的change事件!");
                $("#search-ItemNames").html('<option value="">请选择</option>');
                var ids = $(this).val();
                if (ids == "" || ids == null) {
                    return;
                }
                nmGetItemInfo(['#search-ItemNames'], ids.join(',')); //小品类
                nmGetMaterialIDs();
            });

            $(document).on("change", "#search-ItemNames", function () {
                nmGetMaterialIDs();
            });

            $('#text_AdjustStartShipDate').datepicker({
                format: "yyyy-mm-dd",
                language: "zh-CN",
                autoclose: true,
                todayHighlight: true,
                startDate: new Date()
            })
            var dataList = [];
            IsCreate = true;
            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                    [
                        {
                            trClass: '',
                            children: [
                                { tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: 'hide' },
                                { tdText: '供应商', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShortName td-w100' },
                                { tdText: '仓库', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShortName ' },
                                { tdText: '订单号', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'OrderBillNo' },
                                { tdText: '货品名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MaterialShortName' },
                                { tdText: '货号', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MaterialID' },
                                { tdText: '计划<br/>到货日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'StartShipDate td-w100' },
                                { tdText: '计划<br/>到货数量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RemainQty td-w70' },
                                { tdText: '调整后<br/>到货日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'AdjustStartShipDate td-w100' },
                                { tdText: '调整后<br/>到货数量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'AdjustRemainQty td-w70' }
                            ]
                        }
                    ]);
            }


            //只能输入数字
            $('#text_AdjustRemainQty').bind('input propertychange', function () {
                var myReg = /^[\u4e00-\u9fa5]+$/;
                if (myReg.test($(this).val())) {
                    $(this).val("");
                }
                if (isNaN($(this).val())) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return;
                }
                //将中文替换掉
                $(this).val($(this).val().replace(/[^\x00-\xff]/g, ''));

                //最多为9999家
                if (parseInt($(this).val()) > 10000) {
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                    return
                }
            });

            var pageList = [];
            //获取列表
            var loadList = function () {
                $('#editBtn').attr('disabled', 'disabled');
                SetQueryValues();
                pageControl.init('ReturPlan', 'GetReturPlanList', {
                    ShortNames: q_shortNames,
                    KindNames: q_kindNames,
                    ItemNames: q_itemNames,
                    MaterialIDs: $('#search-MaterialIDs').val(),
                    Page: page,
                    Size: 50,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            //有值，可以编辑  在选择后控制
                            //$('#editBtn').removeAttr('disabled');
                            dataList = result.data.Items;
                            var IsEmpty = '';
                            result.data.Items.map(function (item, i) {
                                var tempChild = [];
                                var yellowClassname = '';
                                var redClassname = '';
                                if (item.ChangeFlag == 1) {
                                    yellowClassname = 'font-yellow';
                                } else if (item.ChangeFlag == 2) {
                                    redClassname = 'font-red';
                                }
                                tempChild = [
                                    { tdText: (item.ShortName || IsEmpty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('ShortName ') },
                                    { tdText: (item.StockName || IsEmpty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('StockName ') },
                                    { tdText: (item.OrderBillNo || IsEmpty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('OrderBillNo ') },
                                    { tdText: (item.MaterialShortName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('MaterialShortName ') },
                                    { tdText: (item.MaterialID || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('MaterialID ') },
                                    { tdText: (item.StartShipDate == null ? IsEmpty : new Date(item.StartShipDate).format('yyyy-MM-dd')), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('StartShipDate ' + redClassname) },
                                    { tdText: (item.RemainQty || IsEmpty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('RemainQty ' + yellowClassname) },
                                    { tdText: (item.AdjustStartShipDate == null ? IsEmpty : new Date(item.AdjustStartShipDate).format('yyyy-MM-dd')), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('AdjustStartShipDate ' + redClassname) },
                                    { tdText: (item.AdjustRemainQty || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: ('AdjustRemainQty ' + yellowClassname) }
                                ];
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even ' : 'gradeX footable-odd '), children: tempChild
                                };
                                tBody.push(tempTr);
                            });
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                    //选择全部插件
                    $(".footable").icheckAll({
                        checkObj: ".checkPlan",//表格下面的选择控件对象 选择器
                        checkAllObj: "#checkAllPlan",//全选 选择器
                        clickoutBoxCheck: false,//点击行 不选中
                        checkboxMargin: "4px 0 0 0 "//上右下左
                    });
                });
            }

            //页面加载
            loadList();

            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });
            //获取Erp按钮
            $('.btns-container').on('click', '#btn_queryErpData', function () {
                page = 1;
                layer.msg('玩命下载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ReturPlan', 'SyncReturPlanByERP', {}, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal("获取成功!", '', 'success');
                        //刷新列表
                        loadList()
                    }
                });
                ;
            });
            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                $('.editTitle').text('编辑数据');
                $('#addModuleBtn').show();
                resetInput();
                IsCreate = false;
                loadDetail();
            });

            var resetInput = function () {
                $('#text_ShortName').val("");
                $('#text_OrderBillNo').val("");
                $('#text_MaterialShortName').val("");
                $('#text_MaterialID').val("");
                $('#text_StartShipDate').val("");
                $('#text_RemainQty').val("");
                $('#text_AdjustStartShipDate').val("");
                $('#text_AdjustRemainQty').val("");
                $('#text_OldAdjustStartShipDate').val("");
                $('#text_OldAdjustRemainQty').val("");
            }

            var ShortName, OrderBillNo, MaterialShortName, MaterialID, StartShipDate, RemainQty, AdjustStartShipDate, AdjustRemainQty, StockName;
            //选中按钮信息
            $('#pageList').on('click', 'tr', function () {
                ShortName = $(this).find('.ShortName').text();
                StockName = $(this).find('.StockName').text();
                OrderBillNo = $(this).find('.OrderBillNo').text();
                MaterialShortName = $(this).find('.MaterialShortName').text();
                MaterialID = $(this).find('.MaterialID').text();
                StartShipDate = $(this).find('.StartShipDate').text();
                RemainQty = $(this).find('.RemainQty').text();
                AdjustStartShipDate = $(this).find('.AdjustStartShipDate').text();
                AdjustRemainQty = $(this).find('.AdjustRemainQty').text();
                //解除禁止编辑和删除按钮
                if (!isNaN(OrderBillNo)) {
                    //$('#deleteBtn').removeAttr('disabled');
                }
                $('#editBtn').removeAttr('disabled');
                //选中样式切换
                $('#pageList tr').removeClass('check');
                $(this).addClass('check');
            });

            //获取选中行的内容,填充到打开的框内
            var loadDetail = function () {
                //有的会加载出来两个 
                if (OrderBillNo == "") {
                    swal("数据异常，订单编号不能为空，请刷新页面重试", '', 'error');
                    return false;
                }
                /*
                赋值
                */
                $('#text_ShortName').val(ShortName);
                $('#text_StockName').val(StockName);
                $('#text_OrderBillNo').val(OrderBillNo);
                $('#text_MaterialShortName').val(MaterialShortName);
                $('#text_MaterialID').val(MaterialID);
                $('#text_StartShipDate').val(StartShipDate);
                $('#text_RemainQty').val(RemainQty);
                $('#text_AdjustStartShipDate').val(AdjustStartShipDate);
                $('#text_AdjustRemainQty').val(AdjustRemainQty);

                //保存旧的
                $('#text_OldAdjustStartShipDate').val(AdjustStartShipDate);
                $('#text_OldAdjustRemainQty').val(AdjustRemainQty);
            }

            //弹窗的保存操作
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('.form-horizontal')) {
                    return false;
                }
                var action = "";
                var successText = "";
                if (IsCreate) {
                    action = "Insert";
                    successText = '新增成功';
                    $('#ShopPlanID').val("0");
                }
                else {
                    action = "Update";
                    successText = '编辑成功';
                    //效验是否未更改内容
                    if (CheckIsChang()) {
                        tipCss($(this), "数据未更改"); return false;
                    }
                }
                if ($('#ShopNum').val() <= 0) {
                    tipCss($(this), "数量不能小于零"); return false;
                }


                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ReturPlan', action, {
                    OrderBillNo: $('#text_OrderBillNo').val(),
                    MaterialID: $('#text_MaterialID').val(),
                    AdjustStartShipDate: $('#text_AdjustStartShipDate').val(),
                    AdjustRemainQty: $('#text_AdjustRemainQty').val()
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框  
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList();
                    }
                });
            });
            //修改时 验证是否有修改内容
            var CheckIsChang = function () {
                if ($('#text_AdjustStartShipDate').val() == 0) {
                    return false;
                }

                if ($('#text_AdjustRemainQty').val() == 0) {
                    return false;
                }
                var OldAdjustStartShipDate = $('#text_OldAdjustStartShipDate').val();
                var OldAdjustRemainQty = $('#text_OldAdjustRemainQty').val();

                var AdjustStartShipDate = $('#text_AdjustStartShipDate').val();
                var AdjustRemainQty = $('#text_AdjustRemainQty').val();

                if (OldAdjustStartShipDate == AdjustStartShipDate && OldAdjustRemainQty == AdjustRemainQty)
                    return true;
                return false;
            }
        });
    </script>
</asp:Content>



